package drawingtools;
import program.*;

import gui.DrawingPanel;

import java.awt.event.MouseEvent;

import diagramobjects.DiagramObject;
import diagramobjects.DiagramObjects;
import diagramobjects.UseCase;

import program.DatabaseConnection;


public class UseCaseTool extends DrawingTool{
	
	protected DiagramObjects GeomObjs;
	protected DiagramObject tempObject;
	protected DrawingPanel DrawPanel;
	
	public UseCaseTool(DiagramObjects go, DrawingPanel dp)
	{
		GeomObjs = go;
		DrawPanel = dp;
	}
	
	

	@Override
	public void mousePressed(MouseEvent arg0) {
		super.mousePressed(arg0);
		System.out.println("mouseClicked, clickcount:" + ClickCount);
		
		//if (ClickCount == 0) 
		{
			GeomObjs.AddGeometricObjectToPanel(new UseCase(arg0.getX(), arg0.getY(),0,0, "UseCase", 0));
			DrawPanel.addSelected();
			tempObject = GeomObjs.GetLastGeometricbjectFromPanel();
			//((Line)tempObject).Print();
			IncreaseClickCount();
			DatabaseConnection.AddUseCase(tempObject.ToDatabase());
			//DrawPanel.repaint();

		}

	}



	@Override
	public void mouseDragged(MouseEvent e) {
		super.mouseDragged(e);
		System.out.println("UseCaseTool->mouseDragged(MouseEvent e)");
		Double sizex = new Double(e.getX() - tempObject.getPositionX());
		Double sizey = new Double(e.getY() - tempObject.getPositionY());
		if (sizex <0)
			sizex = 0.0;
		if (sizey < 0)
			sizey = 0.0;
		
		//if (sizex>sizey)
		sizey = sizex*0.6;
		//else
			//sizex = 1.4*sizey;
			
		//tempObject.SetSize(sizex.intValue(), sizey.intValue());
		
		tempObject.SetSize(sizex.intValue(), sizey.intValue());
		Double textsize = java.lang.Math.sqrt(java.lang.Math.sqrt((sizex*sizex*sizex+sizey*sizey)));
		textsize *= 0.5;
		tempObject.SetTextSize( textsize.intValue());
		tempObject.Print();
		DrawPanel.repaint();
		

	}




}
